/*
 * Created by JFormDesigner on Wed Nov 20 14:35:38 CST 2024
 */

package com.hafu.view.kehu;

import com.hafu.dao.KhInfoDao;
import com.hafu.model.KhInfo;
import com.hafu.service.KhInfoService;
import com.hafu.util.StringUtil;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author 姜在虞
 */
public class AddKeHuFrm extends JFrame {
    public AddKeHuFrm() {
        initComponents();
    }



    private void tijiaobutton1(ActionEvent e) {
        // TODO add your code here
        String name=textField2.getText();
        String tel=textField3.getText();
        if(StringUtil.isEmpty(name)){
            JOptionPane.showMessageDialog(null, "客户名称不能为空");
        }
        if(StringUtil.isEmpty(tel)){
            JOptionPane.showMessageDialog(null, "客户电话不能为空");
            return;
        }
        KhInfo khInfo=new KhInfo(name, tel);

        KhInfoService khInfoService = new KhInfoService();
        Boolean aBoolean = khInfoService.addKhInfo(khInfo);
        if(aBoolean){
            JOptionPane.showMessageDialog(null, "添加成功");
            this.dispose();
        }else{
            JOptionPane.showMessageDialog(null, "添加失败");
        }
    }

    private void button1(ActionEvent e) {
        // TODO add your code here
    }



    

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        textField1 = new JTextField();
        textField2 = new JTextField();
        label1 = new JLabel();
        label2 = new JLabel();
        textField3 = new JTextField();
        tijiaobutton1 = new JButton();

        //======== this ========
        setTitle("\u6dfb\u52a0\u5ba2\u6237\u8868\u5355");
        Container contentPane = getContentPane();

        //---- label1 ----
        label1.setText("\u5ba2\u6237\u540d\u5b57");

        //---- label2 ----
        label2.setText("\u5ba2\u6237\u7535\u8bdd");

        //---- tijiaobutton1 ----
        tijiaobutton1.setText("\u63d0\u4ea4");
        tijiaobutton1.addActionListener(e -> tijiaobutton1(e));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap(138, Short.MAX_VALUE)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addComponent(label2, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 97, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label1, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE))
                    .addGap(33, 33, 33)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                        .addComponent(textField3, GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
                    .addGap(170, 170, 170))
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(197, 197, 197)
                            .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 0, GroupLayout.PREFERRED_SIZE))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(174, 174, 174)
                            .addComponent(tijiaobutton1, GroupLayout.PREFERRED_SIZE, 231, GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(203, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(89, 89, 89)
                    .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 4, GroupLayout.PREFERRED_SIZE)
                    .addGap(16, 16, 16)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE))
                    .addGap(61, 61, 61)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(textField3, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label2, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
                    .addGap(64, 64, 64)
                    .addComponent(tijiaobutton1)
                    .addContainerGap(109, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JTextField textField1;
    private JTextField textField2;
    private JLabel label1;
    private JLabel label2;
    private JTextField textField3;
    private JButton tijiaobutton1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
